package com.news.gpb.service.impl;

import com.news.gpb.dao.CollectDao;
import com.news.gpb.dao.LikeDao;
import com.news.gpb.entity.Coll;
import com.news.gpb.entity.Like;
import com.news.gpb.entity.User;
import com.news.gpb.dao.UserDao;
import com.news.gpb.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("userService")
public class UserServiceImpl implements UserService {

    @Autowired
    UserDao userDao;
    @Autowired
    LikeDao likeDao;
    @Autowired
    CollectDao collectDao;

    @Override
    public User getUser(User user) {
        return userDao.getUser(user);
    }

    @Override
    public String addUser(User user) {
        User us = userDao.getUserByEmail(user.getUser_email());
        if(us!=null)
            return "existed";
        else
        {
            if(userDao.insertUser(user)!=null)
            {
                System.out.println(user.getUser_id());
                return "success";
            }
//                return "success";
            else return "error";
        }
    }

    @Override
    public String editUser(User user) {
        Integer res = userDao.editUser(user);
        if(res!=null&&res!=0)
            return "ok";
        else return "error";
    }

    @Override
    public int countLike(int user_id) {
         return likeDao.countLike(user_id);
    }

    @Override
    public int countCollect(int user_id) {
        return collectDao.countCollect(user_id);
    }

    @Override
    public User getUserById(User user) {
        return userDao.getUserById(user.getUser_id());
    }
}
